﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class FormPackages : Form
    {
        public FormPackages()
        {
            InitializeComponent();
        }


        /// Validation of the input information

        SqlConnection myConn = new SqlConnection("server=(local);database=TravelExperts;integrated security=SSPI");

        private bool validateData()
        {
            //Packages myPackage = new Packages();

            if (double.Parse(txtAgencyComm.Text) > double.Parse(txtPkgPrice.Text))
            {
                MessageBox.Show("Agency commision can not be greater than the base price");
                return false;
            }

            if (dtpPkgStart.Value > dtpPkgEnd.Value)
            {
                MessageBox.Show(" End of Package date can not be later than the start of Package date");
                return false;
            }

            if (txtPkgName.Text == "")
            {
                MessageBox.Show("Package name can not be null");
                return false;
            }

            if (txtPkgDescription.Text == "")
            {
                MessageBox.Show("Description can not be null");
                return false;
            }

            return true;

        }

        ///Get all the information for insert into database

        private Packages PackageDetails()
        {
            Packages myPackage = new Packages();
            if (validateData())
            {
                myPackage.PackageId = int.Parse(txtPkgId.Text);
                myPackage.PkgName = txtPkgName.Text;
                myPackage.PkgStartDate = dtpPkgStart.Value;
                myPackage.PkgEndDate = dtpPkgEnd.Value;
                myPackage.PkgBasePrice = decimal.Parse(txtPkgPrice.Text);
                myPackage.PkgDesc = txtPkgDescription.Text;
                myPackage.PkgAgencyCommission = decimal.Parse(txtAgencyComm.Text);
            }
            return myPackage;
        }
        ////////////////////  end of validation and package details/////////////////////////////
        private void eXITToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        ////////////////////exit application////////////////////////////////////////////////////

        private void PopulateCmb()
        {
            List<Products> products = new DbAccess().SelectProducts();
            List<Suppliers> suppliers = new DbAccess().SelectSuppliers();

            foreach (Products entry in products)
            { this.cmbSearchProducts.Items.Add(entry); }

            foreach (Suppliers entry in suppliers)
            { this.cmbSearchSuppliers.Items.Add(entry); }

        }

        private void FormPackages_Load(object sender, EventArgs e)
        {
            PopulateCmb();
        }

    }
}